<template>
    <div class="kzjwcgzltj">
        <div class="kzjwcgzltj-top">
            <el-form :model="form" ref="form" label-width="80px" :inline="true" size="normal">
                <el-form-item label="行政区划">
                    <el-cascader v-model="form.addvcd" :options="xzqhdata" :props="xzqhprop" ref="xzqh"
                        @change="xzqhorgChange" :clearable="true"></el-cascader>
                </el-form-item>
                <el-form-item label="查询时间">
                    <!-- <el-date-picker v-model="form.tm" type="daterange" :start-placeholder="stm" :end-placeholder="etm"
                        value-format="yyyy-MM-dd" format="yyyy-MM-dd">
                    </el-date-picker> -->
                    <el-date-picker v-model="form.tm" type="daterange" align="right" unlink-panels range-separator="至"
                        :start-placeholder="stm" :end-placeholder="etm" value-format="yyyy-MM-dd" format="yyyy-MM-dd">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div class="top-button">
                <el-button type="primary" size="default" @click="chaxun"><i class="iconfont icon-sousuo"></i> 查
                    询</el-button>
                <el-button type="primary" size="default" @click="chongzhi"><i class="el-icon-refresh"></i> 重
                    置</el-button>
                <el-button type="primary" size="default" @click="daochu"><i class="el-icon-upload2"></i> 导 出</el-button>
            </div>
        </div>
        <div class="kzjwcgzltj-middle">
            <el-table class="tableBox" :data="tableData" border stripe height="90%" :row-class-name="tableRowClassName"
                :header-cell-style="{ background: '#b2dffe', color: '#000' }" style="width: 100%">
                <el-table-column type="index" align="center" label="序号" width="55" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <div v-text="pagesize * (currentPage - 1) + 1 + scope.$index"></div>
                    </template>
                </el-table-column>
                <el-table-column prop="addvnm" label="行政区划" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="rate" label="整编工作完成百分比(%)" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="count" label="空值数量统计" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <a href="#" @click="kzsldhkxs(scope.row)">{{ scope.row.count }}</a>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <i class="iconfont icon-chakan" title="查看" @click="chakandhk(scope.row)"></i>
                    </template>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page.sync="currentPage" :page-size="pagesize" layout="total, prev, pager, next" :total="total">
                </el-pagination>
            </div>
        </div>
        <!-- 空值数量对话框 -->
        <el-dialog class="kzsldhk" :visible.sync="dialogVisible" width="80%" :append-to-body="true">
            <div slot="title" class="dialog-title">
                <div class="button-right">
                    <span>{{ this.kzsldhktitle }}空值监测站信息统计</span>
                    <!-- <i class="el-icon-circle-close"></i>; -->
                </div>
            </div>
            <div class="center">
                <el-table class="tableBox" :data="tableData1" :row-class-name="tableRowClassName"
                    :header-cell-style="{ background: '#b2dffe', color: '#000' }" stripe border style="width:100%">
                    <el-table-column prop="jbxx" label="基本信息" width="180">
                        <el-table-column prop="addvnm" label="行政区划" align="center" :show-overflow-tooltip="true">
                        </el-table-column>
                        <el-table-column prop="rate" label="整编工作完成百分比(%)" align="center" :show-overflow-tooltip="true">
                        </el-table-column>
                        <el-table-column prop="count" label="空值数量" align="center" :show-overflow-tooltip="true">
                        </el-table-column>
                    </el-table-column>
                </el-table>
                <el-table class="tableBox" :data="tableData2" stripe height="235" :row-class-name="tableRowClassName"
                    :header-cell-style="{ background: '#b2dffe', color: '#000' }" border style="width: 100%">
                    <el-table-column prop="date" width="180">
                        <template slot="header">
                            {{ this.kzsldhktitle }}空值监测站信息统计表
                        </template>
                        <el-table-column type="selection" align="center" width="50">
                        </el-table-column>
                        <el-table-column label="序号" type="index" width="55" align="center">
                        </el-table-column>
                        <el-table-column prop="stcd" label="测站编码" width="140" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <el-table-column prop="stnm" label="测站名称" width="180" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <el-table-column prop="addvnm" label="行政区划" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <el-table-column prop="stlc" label="监测站位置" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <el-table-column prop="count" label="空值数量" width="80" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <!-- <el-table-column label="操作" align="center" width="60" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <i class="el-icon-delete" title="下载" @click="xiazai(scope.row)"></i>&nbsp;
                            </template>
                        </el-table-column> -->
                    </el-table-column>
                </el-table>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="sldhkdc"><i class="iconfont icon-xiazai-" title="下载"></i>&nbsp;下 载
                </el-button>
            </span>
        </el-dialog>
        <!-- 查看对话框 -->
        <el-dialog class="kzsldhk" :visible.sync="ckdialogVisible" width="80%" :append-to-body="true">
            <div slot="title" class="dialog-title">
                <div class="button-right">
                    <span>{{ this.ckdhktitle }}整编完成工作量统计</span>
                    <!-- <i class="el-icon-circle-close"></i>; -->
                </div>
            </div>
            <div class="center">
                <el-table class="tableBox" :data="chakanData1" :row-class-name="tableRowClassName"
                    :header-cell-style="{ background: '#b2dffe', color: '#000' }" stripe border style="width:100%">
                    <el-table-column prop="jbxx" label="基本信息" width="180">
                        <el-table-column prop="addvnm" label="行政区划" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <el-table-column prop="rate" label="整编工作完成百分比(%)" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                    </el-table-column>
                </el-table>
                <el-table class="tableBox" :data="chakanData2" stripe height="235" :row-class-name="tableRowClassName"
                    :header-cell-style="{ background: '#b2dffe', color: '#000' }" border style="width: 100%">
                    <el-table-column prop="date" width="180">
                        <template slot="header">
                            {{ this.ckdhktitle }}监测站整编工作完成进度统计表
                        </template>
                        <el-table-column label="序号" type="index" align="center" width="55">
                        </el-table-column>
                        <el-table-column prop="stcd" label="测站编码" width="140" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <el-table-column prop="stnm" label="测站名称" width="140" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <el-table-column prop="addvnm" label="行政区划" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <el-table-column prop="stlc" label="监测站位置" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                        <el-table-column prop="rate" label="整编工作完成百分比(%)" :show-overflow-tooltip="true" align="center">
                        </el-table-column>
                    </el-table-column>
                </el-table>
            </div>
        </el-dialog>
    </div>
</template>
<script>
// 列表、行政区划、数量对话框列表、查看对话框列表
import { zbcgkzjwcgzllb, xzqhlist, zbcgkzjwcgzlsllb, zbcgkzjwcgzldc, zbcgkzjwcgzldhkdc } from '@/api/index'
import exprotFile from "@/utils/exportFile"
export default {
    data() {
        return {
            form: {
                addvcd: '220000',//行政区划
                tm: [],//时间
                stcd: '',
                stnm: '',
            },
            tableData: [],
            // 底部页码
            pagesize: 10,
            currentPage: 1,
            total: 10,
            xzqhdata: [],//行政区划
            xzqhprop: {
                label: "addvnm",
                value: "addvcd",
                children: "addvcds",
                checkStrictly: true,
            },
            dialogVisible: false,//空值对话框
            ckdialogVisible: false,//查看对话框
            tableData1: [],//空值对话框的表格数据1
            tableData2: [],//空值对话框的表格数据2
            chakanData1: [],//查看对话框第一个表格数据
            chakanData2: [],//查看对话框第二个表格数据
            kzsldhktitle: '',//空值数量对话框title
            ckdhktitle: '',//查看对话框title
            stm: '',//开始时间
            etm: '',//结束时间
            addvcds: '',//数量对话框下载参数
        }
    },
    mounted() {
        this.getriqi();//获取顶部的时间段js
        this.zbcgkzjwcgzllb();//获取表格数据
        this.xzqhlist();//获取行政区划
    },
    methods: {
        // 获取顶部的时间段
        // getriqi() {
        //     var dqdate = new Date()
        //     var dqday = dqdate.getDate()
        //     var dqyear = dqdate.getFullYear()
        //     var dqmonth = dqdate.getMonth() + 1
        //     // console.log(dqyear, dqmonth)
        //     // console.log(dqday)
        //     if (dqmonth < 10) {
        //         dqmonth = "0" + dqmonth
        //     }
        //     if (dqday < 10) {
        //         dqday = "0" + dqday
        //     }
        //     if (dqday <= 5) {
        //         var cemon = dqmonth - 1
        //         if (cemon - 1 == 0) {
        //             var ceyea = dqyear
        //             // cemon = 12
        //             if (cemon == 11) {
        //                 cemon = 12
        //                 ceyea = dqyear - 1
        //             }
        //         }
        //         switch (cemon) {
        //             case 1:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "31";
        //                 break;
        //             case 2:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "28";
        //                 break;
        //             case 3:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "31";
        //                 break;
        //             case 4:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "30";
        //                 break;
        //             case 5:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "31";
        //                 break;
        //             case 6:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "30";
        //                 break;
        //             case 7:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "31";
        //                 break;
        //             case 8:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "31";
        //                 break;
        //             case 1:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "31";
        //                 break;
        //             case 9:
        //                 this.form.tm = ceyea + "-0" + cemon + "-" + "01," + ceyea + "-0" + cemon + "-" + "30";
        //                 break;
        //             case 10:
        //                 this.form.tm = ceyea + "-" + cemon + "-" + "01," + ceyea + "-" + cemon + "-" + "31";
        //                 break;
        //             case 11:
        //                 this.form.tm = ceyea + "-" + cemon + "-" + "01," + ceyea + "-" + cemon + "-" + "30";
        //                 break;
        //             case 12:
        //                 this.form.tm = ceyea + "-" + cemon + "-" + "01," + ceyea + "-" + cemon + "-" + "31";
        //                 break;
        //         }
        //     } else if (dqday => 6) {
        //         this.form.tm = dqyear + "-" + dqmonth + "-" + "01," + dqyear + "-" + dqmonth + "-" + dqday
        //     }
        //     this.form.tm = this.form.tm.split(",")
        //     // console.log(this.form.tm[0])
        //     this.stm = this.form.tm[0]
        //     this.etm = this.form.tm[1]
        // },
        getriqi() {
            let nowdays = new Date()
            let day = nowdays.getDate()
            let year = nowdays.getFullYear()
            let month = nowdays.getMonth()
            if (day <= 15) {
                month = month - 1
            }
            if (day >= 16) {
                month = month
            }
            if (month === 0) {
                month = 11
                year = year - 1
            }
            if (month < 10) {
                month = '0' + month
            }
            let yDate = new Date(year, month, 0)
            let startDareTime = year + '-' + month + '-01'
            let endDateTime = year + '-' + month + '-' + yDate.getDate() + ' '
            // console.log(startDareTime, endDateTime);
            this.form.tm[0] = startDareTime
            this.form.tm[1] = endDateTime
            this.stm = this.form.tm[0]
            this.etm = this.form.tm[1]
            // console.log(this.form.tm);
        },
        // 获取行政区划
        async xzqhlist() {
            const addvcd = '220000'
            const res = await xzqhlist(addvcd)
            // console.log(res.data.data);
            this.xzqhdata = res.data.data
        },
        // 获取表格数据
        async zbcgkzjwcgzllb() {
            const zbcgkzobj = {
                addvcd: '220000',
                addvcdArray: [],
                etm: this.form.tm[1],
                pageInfo: {
                    pageIndex: this.currentPage,
                    pageSize: this.pagesize
                },
                stcd: this.form.stcd,
                stcdArray: [],
                stm: this.form.tm[0],
                stnm: this.form.stnm
            }
            const res = await zbcgkzjwcgzllb(JSON.stringify(zbcgkzobj))
            // console.log(res);
            this.tableData = res.data.data.list
            this.total = res.data.data.total
        },
        handleSizeChange(val) {
            // console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            // console.log(`当前页: ${val}`);
            this.currentPage = val
            // this.zbcgkzjwcgzllb();
            const zbcgkzobj = {
                addvcd: this.form.addvcd,
                addvcdArray: [],
                etm: this.form.tm[1],
                pageInfo: {
                    pageIndex: this.currentPage,
                    pageSize: this.pagesize
                },
                stcd: this.form.stcd,
                stcdArray: [],
                stm: this.form.tm[0],
                stnm: ''
            }
            zbcgkzjwcgzllb(JSON.stringify(zbcgkzobj)).then(res => {
                this.tableData = res.data.data.list
                this.total = res.data.data.total
                // console.log(res);
            })
        },
        // 表格的隔行颜色改变
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 == 0) {
                return 'statistiss-row'
            } else {
                return ''
            }
        },
        // 下拉框自动关闭,选择后触发事件
        xzqhorgChange(val) {
            this.form.addvcd = val.slice(-1).toString();
            this.$refs.xzqh.dropDownVisible = false;
        },
        // 空值对话框显示
        kzsldhkxs(row) {
            // console.log(row);
            this.addvcds = row.addvcd
            this.dialogVisible = true
            this.kzsldhktitle = row.addvnm
            let kzsldhkarr = [{
                addvnm: "",
                rate: '',
                count: ''
            }]
            kzsldhkarr.map((item, index, arr) => {
                item.addvnm = row.addvnm
                item.rate = row.rate
                item.count = row.count
            })
            this.tableData1 = kzsldhkarr
            // 第二个表格接口数据获取
            const kzslcxobj = {
                addvcd: row.addvcd,
                addvcdArray: [],
                etm: this.form.tm[1],
                pageInfo: {
                    pageIndex: this.currentPage,
                    pageSize: this.pagesize
                },
                stcd: this.form.stcd,
                stcdArray: [],
                stm: this.form.tm[0],
                stnm: this.form.stnm
            }
            zbcgkzjwcgzlsllb(JSON.stringify(kzslcxobj)).then(res => {
                // console.log(res);
                this.tableData2 = res.data.data
            })
            //     .catch(err => {
            //     console.log(err);
            // })
        },
        // 查看对话框显示
        chakandhk(row) {
            this.ckdialogVisible = true
            this.ckdhktitle = row.addvnm
            let ckdhkarr = [{
                addvnm: '',
                rate: ''
            }]
            ckdhkarr.map((item, index, arr) => {
                item.addvnm = row.addvnm
                item.rate = row.rate
            })
            this.chakanData1 = ckdhkarr
            // 第二个表格接口数据获取
            const kzckdhkobj = {
                addvcd: row.addvcd,
                addvcdArray: [],
                etm: this.form.tm[1],
                pageInfo: {
                    pageIndex: this.currentPage,
                    pageSize: this.pageSize
                },
                stcd: this.form.stcd,
                stcdArray: [],
                stm: this.form.tm[0],
                stnm: this.form.stnm
            }
            // zbcgkzjwcgzlckdhklb(JSON.stringify(kzckdhkobj)).then(res => {
            //     // console.log(res);
            //     this.chakanData2 = res.data.data
            // })
            zbcgkzjwcgzlsllb(JSON.stringify(kzckdhkobj)).then(res => {
                console.log(res);
                this.chakanData2 = res.data.data
                // console.log(this.tableData2);
            })
        },
        // 查询
        chaxun() {
            const zbcgkzobj = {
                addvcd: this.form.addvcd,
                addvcdArray: [],
                etm: this.form.tm[1],
                pageInfo: {
                    pageIndex: this.currentPage,
                    pageSize: this.pagesize
                },
                stcd: this.form.stcd,
                stcdArray: [],
                stm: this.form.tm[0],
                stnm: ''
            }
            zbcgkzjwcgzllb(JSON.stringify(zbcgkzobj)).then(res => {
                this.tableData = res.data.data.list
                this.total = res.data.data.total
                // console.log(res);
            })
        },
        // 重置
        chongzhi() {
            this.form.addvcd = '220000'
            // this.form.tm = ''
            this.currentPage = 1
            this.pagesize = 10
            this.zbcgkzjwcgzllb()
        },
        // 导出
        daochu() {
            const kzdaochuobj = {
                addvcd: '220000',
                addvcdArray: [],
                etm: this.form.tm[1],
                pageInfo: {
                    pageIndex: this.currentPage,
                    pageSize: this.pagesize
                },
                stm: this.form.tm[0],
                stcd: this.form.stcd,
                stnm: this.form.stnm
            }
            zbcgkzjwcgzldc(JSON.stringify(kzdaochuobj)).then(res => {
                // console.log(res);
                exprotFile.getExcel(res.data, "空值与完成工作量数据统计");
            })
        },
        // 空值数量对话框导出
        sldhkdc() {
            // this.dialogVisible = false
            const kzdaochuobj = {
                addvcd: this.addvcds,
                addvcdArray: [],
                etm: this.form.tm[1],
                pageInfo: {
                    pageIndex: this.currentPage,
                    pageSize: this.pagesize
                },
                stm: this.form.tm[0],
                stcd: this.form.stcd,
                stnm: this.form.stnm
            }
            // console.log(kzdaochuobj);
            zbcgkzjwcgzldhkdc(JSON.stringify(kzdaochuobj)).then(res => {
                // console.log(res);
                exprotFile.getExcel(res.data, "空值数量数据统计");
            })
        }
    }
}
</script>
<style lang="scss" scoped>
html,
body {
    height: 100%;
}

.kzjwcgzltj {
    width: 100%;
    height: 100%;
    box-sizing: border-box;

    ::v-deep .kzjwcgzltj-top {
        width: 97%;
        height: 10%;
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        box-sizing: border-box;
        /* border: 1px solid red; */

        .el-form {
            /* width: 75%; */
            height: 100%;
            float: left;

            .el-form-item {
                padding-top: 10px;
                padding-right: 10px;

                .el-form-item__label {
                    background-color: #0055ab;
                    color: #fff;

                    .el-input {
                        width: 100%;

                        .el-input__inner {
                            width: 100%;
                        }
                    }
                }
            }
        }

        .top-button {
            /* width: 25%; */
            height: 100%;
            padding-top: 10px;
            float: right;

            .el-button {
                background-color: #0055ab;
                color: #fff;

                .iconfont {
                    font-size: 14px;
                }
            }
        }
    }

    ::v-deep .kzjwcgzltj-middle {
        width: 97%;
        height: 90%;
        margin: 0 auto;
        /* border: 1px solid red; */
        box-sizing: border-box;

        .el-table {
            width: 100%;
            height: 90%;
            background-color: rgb(243, 243, 243);
            padding-top: 10px;

            .el-table__header-wrapper {}

            .el-table__body-wrapper {
                .iconfont {
                    cursor: pointer;
                }
            }
        }

        .bottom {
            width: 100%;
            height: 10%;

            .el-pagination {
                position: absolute;
                bottom: 3%;
                right: 6%;
            }
        }
    }
}

/* 控制top表单的宽度 */
/deep/ .el-input {
    width: 100%;

    .el-input__inner {
        width: 100%;
    }
}

// 滚动条的宽度
/deep/ .el-table__body-wrapper::-webkit-scrollbar {
    width: 6px; // 横向滚动条
    height: 2px; // 纵向滚动条 必写
}

// 滚动条的滑块
/deep/ .el-table__body-wrapper::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 3px;
}


/* 表格的行高 */
/deep/ .tableBox {
    th {
        padding: 0 !important;
        height: 50px;
        line-height: 50px;
    }

    td {
        padding: 0 !important;
        height: 40px;
        line-height: 40px;
    }
}

// 鼠标经过颜色
/deep/ .el-table__body tr:hover>td {
    background-color: #d9effe !important;
}

/* 列标题的字体颜色 */
/deep/ .el-table th.el-table__cell>.cell {
    color: #000;
}

/* 内容的字体颜色 */
/deep/ .el-table--enable-row-transition .el-table__body td.el-table__cell {
    color: #000;
}

/* 表格隔行改变的颜色 */
/deep/ .el-table__row.statistiss-row {
    background-color: #f2faff;
}

/* 去掉滚动条上方的小方块背景色 */
/deep/ .kzjwcgzltj-middle .el-table--border th.el-table__cell.gutter:last-of-type {
    background: rgb(243, 243, 243);
    border: none;
}

/* 查看对话框 */
/deep/ .el-dialog {
    width: 80%;
    height: 72%;
    box-sizing: border-box;

    .el-dialog__header {
        height: 12%;

        /* 查看对话框标题的大小和颜色 */
        .dialog-title {
            .button-right {
                span {
                    font-size: 1.25rem;
                    color: #0055ab;
                }
            }
        }
    }


    .el-dialog__body {
        padding: 0 20px;
        margin-top: 10px;
        height: 73%;
        box-sizing: border-box;

        /* 对话框的滚动条上方的背景色 */
        .el-table thead.is-group th.el-table__cell {
            background-color: #b2dffe;
        }
    }

    /* 查看对话框底部下载按钮 */
    .el-dialog__footer {
        width: 100%;
        height: 15%;
        text-align: center;
        box-sizing: border-box;

        .el-button {
            background-color: #0055ab;
            color: #fff;
        }
    }
}

/deep/ .el-dialog__header {
    padding-bottom: 1.25rem;
    background-color: #eee;
    height: 12%;
    box-sizing: border-box;
}
</style>